/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on Oct 15, 2012, 2:37:27 PM
 */

package test.ashen;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import static com.googlecode.javacv.cpp.opencv_core.*;
import java.awt.AWTException;
import java.awt.Robot;
import com.googlecode.javacv.cpp.opencv_calib3d.*;
import com.googlecode.javacv.FrameGrabber.Exception;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.googlecode.javacv.cpp.opencv_core.*;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.opencv_calib3d.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import test.shanika.CalculateHull;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
/**
 *
 * @author Home
 */
public class GUI extends javax.swing.JFrame  {

    /** Creates new form GUI */
    public GUI() {
        initComponents();
    }

    public static IplImage image;

    public static  IplImage getImage() {
        return image;
    }

    public static void setImage(IplImage image) {
        GUI.image = image;
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Skin1 = new javax.swing.JLabel();
        Cam2 = new javax.swing.JLabel();
        Skin2 = new javax.swing.JLabel();
        Cam1 = new javax.swing.JLabel();
        start = new javax.swing.JButton();
        startCamera = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Skin1.setBorder(javax.swing.BorderFactory.createTitledBorder("Skin 1"));

        Cam2.setBorder(javax.swing.BorderFactory.createTitledBorder("CAM 2"));

        Skin2.setBorder(javax.swing.BorderFactory.createTitledBorder("Skin 2"));

        Cam1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Cam1.setBorder(javax.swing.BorderFactory.createTitledBorder("CAM 1"));
        Cam1.setNextFocusableComponent(Cam1);

        start.setText("Start");
        start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startActionPerformed(evt);
            }
        });

        startCamera.setText("Start Camera");
        startCamera.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startCameraActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Skin1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Skin2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Cam1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Cam2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(88, 88, 88)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(start, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(startCamera, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(216, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Cam2, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Cam1, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Skin2, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Skin1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(102, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addComponent(start)
                .addGap(18, 18, 18)
                .addComponent(startCamera)
                .addContainerGap(317, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startCameraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startCameraActionPerformed
        // TODO add your handling code here:
        while(true){
            ImageIcon ic= new ImageIcon(getImage().getBufferedImage());
            getCam1().setIcon(ic);
            this.repaint(10);
        }
    }//GEN-LAST:event_startCameraActionPerformed

    private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed
        // TODO add your handling code here:
        CameraSkin1 cs1 = new CameraSkin1(1);
        new Thread(cs1).start();
    }//GEN-LAST:event_startActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Cam1;
    private javax.swing.JLabel Cam2;
    private javax.swing.JLabel Skin1;
    private javax.swing.JLabel Skin2;
    private javax.swing.JButton start;
    private javax.swing.JButton startCamera;
    // End of variables declaration//GEN-END:variables

    public JLabel getCam1() {
        return Cam1;
    }

    public JLabel getSkin1() {
        return Skin1;
    }

    public JLabel getSkin2() {
        return Skin2;
    }

     public JLabel getCam2() {
        return Cam2;
    }


}
